<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CPU使用率飙高问题排查指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .highlight-box {
            background: linear-gradient(to right, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 2rem 0;
            border-radius: 0.5rem;
        }
        .tool-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            display: inline-block;
            margin: 0.25rem;
            transition: all 0.2s ease;
        }
        .tool-badge:hover {
            transform: scale(1.05);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                <i class="fas fa-tachometer-alt mr-4"></i>CPU使用率飙高问题排查指南
            </h1>
            <p class="text-xl md:text-2xl opacity-90 leading-relaxed max-w-4xl">
                系统化的分析方法，结合工具和经验进行逐步诊断，确保在解决问题的过程中不影响生产环境的稳定性
            </p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">排</span>查CPU使用率飙高的问题需要系统化的分析方法，结合工具和经验进行逐步诊断。最终的解决方案往往是多层次的，包括代码层面的优化、系统配置的调整，以及架构的改进。本指南将带您深入了解完整的排查流程和解决方案。
            </p>
        </div>

        <!-- Diagnostic Flow Chart -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-project-diagram mr-3 text-purple-600"></i>诊断流程图
            </h2>
            <div class="mermaid">
                graph TD
                    A[发现CPU使用率异常] --> B{初步检查}
                    B --> C[确认高CPU进程]
                    C --> D[分析进程内线程]
                    D --> E{问题类型判断}
                    E -->|代码问题| F[代码层面排查]
                    E -->|系统问题| G[系统级别排查]
                    E -->|外部依赖| H[外部服务排查]
                    F --> I[优化方案实施]
                    G --> I
                    H --> I
                    I --> J[监控验证效果]
                    J --> K{问题解决?}
                    K -->|否| D
                    K -->|是| L[总结经验]
                    
                    style A fill:#ff6b6b,stroke:#ff4757,color:#fff
                    style L fill:#4ecdc4,stroke:#00b894,color:#fff
                    style I fill:#667eea,stroke:#5f3dc4,color:#fff
            </div>
        </div>

        <!-- Step by Step Guide -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
            <!-- Step 1 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <span class="step-number text-5xl font-bold mr-4">1</span>
                    <h3 class="text-2xl font-bold text-gray-800">初步检查与确认问题</h3>
                </div>
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-eye text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">观察症状</h4>
                            <p class="text-gray-600">确认问题的具体表现，如系统响应变慢、服务处理能力下降等。判断是偶发性还是持续性的CPU飙高。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-chart-line text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">系统资源监控</h4>
                            <p class="text-gray-600">使用监控工具查看CPU使用情况：</p>
                            <div class="mt-2">
                                <span class="tool-badge"><i class="fas fa-terminal mr-1"></i>top</span>
                                <span class="tool-badge"><i class="fas fa-terminal mr-1"></i>htop</span>
                                <span class="tool-badge"><i class="fas fa-terminal mr-1"></i>vmstat</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 2 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <span class="step-number text-5xl font-bold mr-4">2</span>
                    <h3 class="text-2xl font-bold text-gray-800">确认高CPU消耗的进程</h3>
                </div>
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-search text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">top命令</h4>
                            <p class="text-gray-600">实时查看系统中各个进程的CPU使用情况，快速定位异常进程。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-list-ol text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">ps命令</h4>
                            <p class="text-gray-600">使用命令按CPU使用率排序：</p>
                            <code class="bg-gray-100 text-purple-600 px-3 py-1 rounded mt-2 inline-block text-sm">ps -aux | sort -nrk 3</code>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 3 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <span class="step-number text-5xl font-bold mr-4">3</span>
                    <h3 class="text-2xl font-bold text-gray-800">分析高CPU进程</h3>
                </div>
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-microscope text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">进程内线程分析</h4>
                            <p class="text-gray-600">使用<code class="bg-gray-100 text-purple-600 px-2 py-1 rounded text-sm">top -H</code>查看进程的每个线程CPU使用情况。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-coffee text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">Java程序分析</h4>
                            <p class="text-gray-600">使用<code class="bg-gray-100 text-purple-600 px-2 py-1 rounded text-sm">jstack</code>生成线程堆栈快照，将线程ID转换为十六进制进行匹配。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 4 -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-center mb-6">
                    <span class="step-number text-5xl font-bold mr-4">4</span>
                    <h3 class="text-2xl font-bold text-gray-800">检查代码层面的问题</h3>
                </div>
                <div class="space-y-4">
                    <div class="flex items-start">
                        <i class="fas fa-infinity text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">死循环或繁忙等待</h4>
                            <p class="text-gray-600">检查线程堆栈中是否存在明显的死循环或无效的循环等待。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-lock text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">锁竞争</h4>
                            <p class="text-gray-600">确认是否有大量线程在等待锁资源，导致忙等待状态。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-trash text-purple-600 mt-1 mr-3"></i>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">频繁GC</h4>
                            <p class="text-gray-600">使用<code class="bg-gray-100 text-purple-600 px-2 py-1 rounded text-sm">jstat</code>监控GC频率和时间。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- System Level Issues -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-server mr-3 text-purple-600"></i>系统级问题排查
            </h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="highlight-box">
                    <h3 class="font-bold text-lg mb-3 flex items-center">
                        <i class="fas fa-hdd text-purple-600 mr-2"></i>I/O压力
                    </h3>
                    <p class="text-gray-700">检查磁盘I/O、网络I/O等是否存在瓶颈，这些问题可能间接导致CPU使用率升高。</p>
                </div>
                <div class="highlight-box">
                    <h3 class="font-bold text-lg mb-3 flex items-center">
                        <i class="fas fa-memory text-purple-600 mr-2"></i>内存压力
                    </h3>
                    <p class="text-gray-700">高内存使用可能导致频繁的上下文切换或分页，使用<code class="bg-gray-100 text-purple-600